<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.jspsmart.upload.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="java.io.*" %>
<jsp:directive.page import="com.dao.DB"/>
<jsp:directive.page import="com.orm.TXuesheng"/>
<jsp:directive.page import="java.sql.ResultSet"/>
<jsp:directive.page import="com.service.GetListService"/>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
  </head>
  
  <body> 
      <% 
     		String sql="select * from t_xuesheng";
     		GetListService gl = new GetListService();
	 		List xueshengList = gl.getXueshengList(sql);
			
			
            HSSFWorkbook wb = new HSSFWorkbook();
			HSSFSheet sheet = wb.createSheet("new sheet");
			
			HSSFRow row = sheet.createRow(0);
			HSSFCell cell=row.createCell((short)0);
			cell.setCellValue("学号");
					
			cell=row.createCell((short)1);
			cell.setCellValue("姓名");
					
			cell=row.createCell((short)2);
			cell.setCellValue("性别");
			
			cell=row.createCell((short)3);
			cell.setCellValue("入学日期");
			
			cell=row.createCell((short)4);
			cell.setCellValue("身份证号");
			
			cell=row.createCell((short)5);
			cell.setCellValue("所在院系");
			
			cell=row.createCell((short)6);
			cell.setCellValue("联系电话");
			
			cell=row.createCell((short)7);
			cell.setCellValue("添加时间");
			
			cell=row.createCell((short)8);
			cell.setCellValue("当前状态");
			
			for(int i=0;i<xueshengList.size();i++)
			{
				TXuesheng xuesheng = (TXuesheng)xueshengList.get(i);
				
				row=sheet.createRow(i+1);
				cell=row.createCell((short)0);
				cell.setCellValue(xuesheng.getXuehao());
						
				cell=row.createCell((short)1);
				cell.setCellValue(xuesheng.getXingming());
				
				cell=row.createCell((short)2);
				cell.setCellValue(xuesheng.getXingbie());
				
				cell=row.createCell((short)3);
				cell.setCellValue(xuesheng.getRuxue());
				
				cell=row.createCell((short)4);
				cell.setCellValue(xuesheng.getShenfenzheng());
				
				cell=row.createCell((short)5);
				cell.setCellValue(xuesheng.getYuanxi());
				
				cell=row.createCell((short)6);
				cell.setCellValue(xuesheng.getLianxi());
				
				cell=row.createCell((short)7);
				cell.setCellValue(xuesheng.getRiqi());
				
				cell=row.createCell((short)8);
				int zt_xuesheng = xuesheng.getZt_xuesheng();
				if(zt_xuesheng==0)
				{
					cell.setCellValue("办理中");
				}
				else if(zt_xuesheng==1)
				{
					cell.setCellValue("等待系办公室确认");
				}
				else
				{
					cell.setCellValue("已离校");
				}
			}
			
			String fileName = "离校学生明细"+System.currentTimeMillis()+".xls";
			
			String fujianPath="c:\\" + fileName;
			try
			{
				FileOutputStream fileOut = new FileOutputStream(fujianPath);
				wb.write(fileOut);
				fileOut.close();
			} 
			catch (Exception e)
			{
			       e.printStackTrace();
			}
			
          
      
          
          SmartUpload su = new SmartUpload(); // 新建一个SmartUpload对象 

          su.initialize(pageContext); // 初始化 

          su.setContentDisposition(null); 
          // 设定contentDisposition为null以禁止浏览器自动打开文件， 
          //保证点击链接后是下载文件。若不设定，则下载的文件扩展名为 
          //doc时，浏览器将自动用word打开它。扩展名为pdf时，将用acrobat打开

          //su.downloadFile("/uploadPath/file/liu.doc"); // 下载英文文件
          su.downloadFile(fujianPath, null, new String(java.net.URLDecoder.decode(fileName,"UTF-8").getBytes(), "ISO8859-1")); // 下载中文文件
          //downloadFile(String sourceFilePathName, String contentType, String destFileName)
          out.clear();
          out=pageContext.pushBody(); 
      %> 

      
  </body>
</html>
